package com.wx.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class HelloController {

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping(value = "/hello1")
    public String hello1() {
        String re = restTemplate.getForObject("http://eureka-provider/hello", String.class);
        return re;
    }

    @RequestMapping(value = "/hello2")
    @HystrixCommand(fallbackMethod = "defaultFallback")
    public String hello2() {
        String re = restTemplate.getForObject("http://eureka-provider/hello", String.class);
        return re;
    }

    public String defaultFallback() {
        return "断路器打开";
    }
}
